<?php

/* **************************************************************************
File:					category.estategent.php
EstateAgent Improved - a Joomla Component
Copyright:			2004 - 2006 by Darko Selesi

Year: 2007
Improved by: Manos Orfanoudakis - "vosk"
Homepage: 		http://www.eaimproved.eu
Version: 			1.3.x                     
License:			GNU/GPL http://www.gnu.org/copyleft/gpl.html
*************************************************************************** */

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );


class EACategory extends mosDBTable {

  	var $id = null;
  	var $name = null;
  	var $description = null;
  	var $parent = null;
  	var $ordering = null;
  	var $access = null;
  	var $publish_up = null;
  	var $publish_down = null;
  	var $published = 0;

	function EACategory( &$db ) {
    	$this->mosDBTable( '#__estateagent_categories', 'id', $db );
  	}
 	
	function getCatEntries($id=null){
				
		if ($id) {
			$this->id = intval( $id );
		}
		$query  = "SELECT id FROM #__estateagent WHERE cat = '".$this->id."'";
		$this->_db->setQuery($query);
        $result = $this->_db->loadResultArray();
				
		return $result;
	}
	
	function getSubcategories($id=null, $gid=""){
		$today =  mosCurrentDate( $format="%Y-%m-%d" );
		$gid=is_numeric($gid)? "AND access <= $gid" : "";
		if ($id) {
			$this->id = intval( $id );
		}
		$query  = "SELECT * FROM #__estateagent_categories"
					. " WHERE"
					. " ("
					. "\n ((publish_up >= '0000-00-00' AND publish_up <= '$today') AND publish_down >= '$today')"
       				. "\n OR ((publish_up >= '0000-00-00' AND publish_up <= '$today' ) AND (publish_down = '0000-00-00' OR publish_down >= '$today'))"
       				. "\n OR (publish_up = '0000-00-00' AND publish_down = '0000-00-00')"
       				. "\n )"
					. " AND parent = $this->id $gid AND published='1' ORDER BY ordering";
		$this->_db->setQuery($query);
        $result = $this->_db->loadObjectList();
		
		return $result;				
	}
}

?>
